from sqlalchemy import Column,Integer,String,CHAR,DateTime,Float,desc,text
from models.base import db
import time

from models.base import Base


class Sentence(Base):
    __tablename__ = 'sentence'
    id = Column(Integer, primary_key=True, autoincrement=True)
    order_number = Column(String(30),nullable=False)
    sentence_index = Column(CHAR(8),nullable=False)
    content = Column(String(150),nullable=False)
    paragraph_index = Column(Integer,nullable=False)
    is_similar = Column(Integer,nullable=False,default=0)

    @classmethod
    def update_sentence_status(cls,sentence_index,order_number):
        sql = "update sentence set is_similar = 1 where order_number = '%s' and sentence_index in (%s)" % (order_number,','.join(list(map(lambda x: "'%s'" % x, sentence_index))))
        db.execute(sql)
        db.session.commit()

    @classmethod
    def get_sentence(cls, paragraph_index,order_number):
        result = db.query(cls).filter_by(order_number=order_number,paragraph_index=paragraph_index).order_by('id').all()
        return result


